package com.jesper.seckill.config;

import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.util.*;

@Configuration
public class RedissonTestConfig {

    /**
     * 三种方式完成Bean初始化后/销毁前操作
     * 第一种：通过实现InitializingBean/DisposableBean
     * 第二种：通过标签init-method/destroy-method
     * 第三种：通过注解@PostConstruct/@PreDestroy
     */
    @PostConstruct
    public void initRedissonValue(){
//        RedisUtils.incr("aaa");
    }

    public static void main(String[] args) {
        List<String> keyList = Arrays.asList("a","a","c","c","b");
        Map<String, List<String>> resultListMap = new HashMap<>();
        for (String key : keyList){
            if (resultListMap.containsKey(key)){
                List<String> list = resultListMap.get(key);
                list.add(key + list.size());
                resultListMap.put(key,list);
            } else {
                List<String> list = new ArrayList<>();
                list.add(key + 0);
                resultListMap.put(key,list);
            }
        }
        System.out.println(resultListMap.toString());
        //使用stream(判断一个map中是否存在这个key，如果存在则处理value的数据，如果不存在，则创建一个满足value要求的数据结构放到value中)
        Map<String, List<String>> resultListMap1 = new HashMap<>();
        keyList.stream().forEach(newKey ->
                resultListMap1.computeIfAbsent(newKey,k -> new ArrayList<>())
                        .add(newKey + resultListMap1.get(newKey).size()));
        System.out.println(resultListMap1.toString());
    }
}
